<div id="albums">
    {% for album in albums %}
        {% if forloop.first %}<div class="row">{% endif %}
        {% if forloop.counter0|divisibleby:5 and not forloop.first %}
            </div><div class="row">
        {% endif %}

        <a href="{% url album_detail album_id=album.id %}">
            <div class="span2 thumbnail">
                {% with first_photo=album.get_first_photo %}
                    {% ifnotequal first_photo None %}
                        <img src="{{ first_photo.thumb.url }}" alt="{{ album.name }}" />
                    {% endifnotequal %}
                {% endwith %}
                <div class="caption">{{ album.name }} ({{ album.photo_set.all|length }})</div>
            </div>
        </a>

        {% if forloop.last %}</div>{% endif %}
    {% empty %}
        <h4 class="well">There are no albums yet.</h4>
    {% endfor %}
</div>